package com.triones.ljr.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.triones.ljr.entity.dto.LawEnforcementDO;
import com.triones.ljr.entity.vo.LawEnforcementVO;
import com.triones.ljr.service.LawEnforcementService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 执法事项
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/zf")
public class LawEnforcementController extends BaseController {

    private final LawEnforcementService lawEnforcementService;

    /**
     * 列表（分页）
     */
    @SaCheckPermission("system:zf:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<LawEnforcementVO> pageList(LawEnforcementDO dto, PageQuery pageQuery) {
        return lawEnforcementService.pageList(dto, pageQuery);
    }

    /**
     * 新增
     */
    @SaCheckPermission("system:zf:add")
    @Log(title = "执法事项", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody LawEnforcementDO dto) {
        return toAjax(lawEnforcementService.add(dto));
    }

    /**
     * 修改
     */
    @SaCheckPermission("system:zf:edit")
    @Log(title = "执法事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody LawEnforcementDO dto) {
        return toAjax(lawEnforcementService.edit(dto));
    }

    /**
     * 获取详情
     */
    @GetMapping("/{id}")
    public R<LawEnforcementVO> getInfo(@PathVariable Long id) {
        return R.ok(lawEnforcementService.getInfo(id));
    }

    /**
     * 删除
     */
    @SaCheckPermission("system:zf:remove")
    @Log(title = "执法事项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(lawEnforcementService.remove(id));
    }
}
